package com.renwei.yunlong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.renwei.yunlong.R;
import com.renwei.yunlong.bean.contacts.Contact;
import com.renwei.yunlong.global.AppHelper;
import com.renwei.yunlong.view.RoundView;
import com.zyf.fwms.commonlibrary.base.baseadapter.BaseRecyclerViewAdapter;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Project :  yunaandroid.
 * Package name: com.renwei.yunlong.adapter
 * Created by :  Benjamin.
 * Created time: 2017/12/5 15:51
 * Changed by :  Benjamin.
 * Changed time: 2017/12/5 15:51
 * Class description:
 */

public class StartChatListAdapter extends BaseRecyclerViewAdapter<Contact> {

    public StartChatListAdapter(Context context, String companyType) {
        super(context);
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_start_iv, parent, false);
        return new StartChatListAdapter.RcViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        final Contact item = getItem(position);
        if (holder instanceof StartChatListAdapter.RcViewHolder) {
            if (AppHelper.hasContact(item))// TODO: 2017/12/10 代表当前已经选中或未选中 是可点击状态
            {
                if (item != null) {
                    Glide.with(mContext).load(item.getAvatar())
                            .placeholder(R.mipmap.icon_header_default).error(R.mipmap.icon_header_default).into(((RcViewHolder) holder).civ);
                }
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AppHelper.setCheck(item);//删除对应ITEM
                    }
                });
            }
        }
    }

    class RcViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.civ)
        RoundView civ;

        public RcViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
